package first.progr.tc;

import static first.progr.helpstaff.ContactHelper.CREATION;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static first.progr.tc.ContactDataGenerator.loadContactsFromXmlFile;
import first.progr.utils.SortedListOf;

public class ContactCreatingTests extends TestBase{
	
@DataProvider
  public Iterator<Object[]> contactsFromFile() throws IOException {
  return wrapContactsForDataProvider(loadContactsFromXmlFile(new File("contacts.xml"))).iterator();    
}	
	
@Test(dataProvider = "contactsFromFile")
  public void testNewContactCreating(ContactData cont1) throws Exception {
    // Save old contacts state 
    SortedListOf<ContactData> oldContactsList = app.getContactHelper().getContacts();
   
    // Actions
    app.getContactHelper().createContact(cont1, CREATION); 
    
    // Save new contacts state
    SortedListOf<ContactData> newContactsList = app.getContactHelper().getContacts();
    
    // Compare states of lists
    assertThat(newContactsList, equalTo(oldContactsList.withAdded(cont1)));
  }
}
